#include "global.h"
#include "term.h"
#include <string.h>
#include <unistd.h>

tb_global_t global = {0};

/* outer call
 * tb_present
 * tb_clear
 * tb_set_cell
 * tb_utf8_char_to_unicode
 * tb_set_input_mode
 * tb_poll_event
 * */

void bytes_puts(fifo_t *f, const char *str)
{
    fifo_add(f, str, strlen(str));
}

void bytes_flush(fifo_t *f)
{
    write(global.tty_fd, f->buf, f->len);
    fifo_del(f, f->len);
}

static int enter_screen()
{
    bytes_puts(&global.out, global.caps[TB_CAP_ENTER_CA]);
    bytes_puts(&global.out, global.caps[TB_CAP_ENTER_KEYPAD]);
    bytes_puts(&global.out, global.caps[TB_CAP_HIDE_CURSOR]);
}

static int exit_screen()
{
}

static int clean_screen()
{
}

int tb_init()
{
    memset(&global, 0, sizeof(global));
    term_init();
    fifo_init(&global.in, 0, NULL);
    fifo_init(&global.out, 0, NULL);
    return 0;
}

int tb_deinit()
{
    fifo_deinit(&global.in);
    fifo_deinit(&global.out);
    term_deinit();
    memset(&global, 0, sizeof(global));
    return 0;
}

int tb_show()
{
}

int tb_clear()
{
}

int tb_poll()
{
    return tb_deinit();
}


int main()
{
    tb_init();

    printf("hello world\n");

    return tb_poll();
}
